// pages/order/detail/detail.js
import {
  findOrderDetailByGoodsId,
  findOrderDetailByCart,
  findOrderAdderss,
} from '../../../utils/api'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    goodsId: '', //商品id
    remarks: '', //备注
    orderDetail: {}, //订单详情信息
    orderAddress: {}, //订单地址信息
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.goodsId) {
      this.setData({
        goodsId: options.goodsId, //商品id
        remarks: options.blessing, //备注信息
      })
      const { goodsId, blessing } = options
      this.getOrderDetailByGoodsId({ goodsId, blessing })
    } else {
      this.getOrderDetailByCart()
    }
  },
  async getOrderDetailByGoodsId(params) {
    try {
      const result = await findOrderDetailByGoodsId(params)
      // console.log(result);
      if (result.code === 200) {
        this.setData({
          orderDetail: result.data,
        })
      }
    } catch (error) {
      console.log(error)
    }
  },
  async getOrderDetailByCart() {
    try {
      const result = await findOrderDetailByCart()
      // console.log(result);
      if (result.code === 200) {
        this.setData({
          orderDetail: result.data,
        })
      }
    } catch (error) {
      console.log(error)
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getOrderAddress()
  },
//获取地址相关的信息数据函数
async getOrderAddress(){
  try {
    const result =await findOrderAdderss()
    console.log(result);
    if(result.code===200){
      this.setData({
        orderAddress:result.data
      })
    }
  } catch (error) {
    console.log(error);
  }
},
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
})
